﻿@{
    Layout = "~/Areas/Admin/Views/_LayoutFramePage.cshtml";
    CurrentUser user = ViewBag.CurrentUser;
    int tableId = ViewBag.TableId;
    IEnumerable<dynamic> fieldData = Html.GetFieldList("pa_tag", "list", user);
}
<div class="current-location">
    <ul>
        <li class="left"><i class="glyphicon glyphicon-home"></i><a href="javascript:void(0)" onclick="location.href=location.href">标签管理/@ViewBag.TableName</a></li>
        <li class="right"><a href="javascript:void(0)" onclick="LoadData()" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a></li>
    </ul>
</div>

<div class="main">
    <table border=0 cellpadding=0 cellspacing=0 class="tb-head">
        <tr>
            <td>
                <div class="btn-group btn-group-sm">
                    <button type="button" class="btn btn-default btn-sm ui-selectInvert">反选</button>
                    <button type="button" class="btn btn-default dropdown-toggle btn-sm" data-toggle="dropdown" aria-expanded="false">
                        菜单
                        <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu" role="menu">
                        <li><a class="ui-dialog" href="javascript:void(0)" data-custom-params="title:'添加标签', url:'@Url.ActionUrl("Add")?tableId=@tableId',width:'90%',height:'90%'">添加</a></li>
                        <li class="divider"></li>
                        <li><a class="ui-ajaxRequest" data-custom-params="type:'post', url:'@Url.ActionUrl("CountTagData")?tableId=@tableId',confirmMsg:'是否确定统计？',successMsg:'关联数据统计中，请稍后查看!'" href="javascript:void(0)">统计关联数据</a></li>
                        <li class="divider"></li>
                        <li><a href="javascript:void(0)" class="ui-deleteMultiple" data-custom-params="url:'@Url.ActionUrl("Delete")',beforeExecute:'BeforeExecuting',callBack:'LoadData'">删除</a></li>
                    </ul>
                </div>
            </td>
            <td align="right">
                <div class=" form-inline form-group-sm">
                    <select id="orderBy" class="ui-queryString form-control ui-queryString-search">
                        <option value="">排序方式</option>
                        <option value="id desc">按id↓</option>
                        <option value="id asc">按id↑</option>
                        @Html.Partial("~/Areas/E/Views/CustomForm/OrderFieldPartial.cshtml", fieldData)
                        <option value="Count asc">按信息总数↑</option>
                        <option value="Count desc">按信息总数↓</option>
                    </select>
                    <select id="s_field" name="s_field" class="btn-xs ui-setName form-control">
                        @Html.Partial("~/Areas/E/Views/CustomForm/SearchFieldPartial.cshtml", fieldData)
                        <option value="name">标签</option>
                    </select>
                    <input type="text" placeholder="搜索关键词" class="form-control ui-keyword ui-queryString">
                    <button type="button" class="btn btn-default btn-sm ui-queryString-search">确定</button>
                </div>
            </td>
        </tr>
    </table>

    <table border=0 cellpadding=0 cellspacing=0 class="table table-bordered form-inline form-group-sm" id="tb_list">
        <thead>
            <tr>
                <td align="center" style="width:40px"><input type="checkbox" title="选择" class="ui-selectInvert" data-custom-params="isReverse:false"></td>
                <td align="center">Id</td>
                <td align="center">标签</td>
                @foreach (var item in fieldData)
                {
                    <td align="center">@item.Remark</td>
                }
                <td align="center">关联数据</td>
                <td align="center">操作</td>
            </tr>
        </thead>
        <tr class="item list-template-item" id="item_{id}">
            <td align="center" style="width:40px"><input type="checkbox" class="checked-item" value="{id}"></td>
            <td align="center">{id}</td>
            <td align=left>{Name}</td>
            @foreach (var item in fieldData)
            {
                int listWords = item.ListWords;
                int fieldId = item.Id;
                string field = item.Name;
                string fieldType = item.FieldType;
                string valueType = item.ValueType;
                string align = "center";
                if (valueType == "nvarchar" || valueType == "text")
                {
                    if (fieldType != "image")
                    {
                        align = "left";
                    }
                }
                <td align="@align">
                    @if (new string[] { "images", "files", "subtable" }.Contains(fieldType))
                    {
                        <span class="sp_@field sp_values" data-value-params="id:{id},fieldId:@fieldId,name:'@field',fieldType:'@fieldType',valueType:'@valueType',listWords:'@listWords'"><i class="fa fa-spinner fa-spin"></i></span>
                    }
                    else
                    {
                        <span class="sp_@field sp_values" data-value-params="id:{id},fieldId:@fieldId,name:'@field',fieldType:'@fieldType',valueType:'@valueType',listWords:'@listWords'">{@field}</span>
                    }
                </td>
            }
            <td align="center">
                <div class="btn-group btn-group-sm ">
                    <button type="button" class="btn btn-default">{Count}</button>
                    <button type="button" class="btn btn-default ui-dialog"  data-custom-params="title: '{name}-关联数据', url:'@Url.ActionUrl("index","TagData")?tagid={id}&tableid={tableid}',width:'90%',height:'90%',shadeClose:true">管理</button>
                </div>
            </td>
            <td align="center">
                <input type="hidden" name="id" value="{id}" />
                <div class="btn-group btn-group-sm">
                    <button class="btn btn-default ui-dialog" data-custom-params="title: '{name}-修改', url:'@Url.ActionUrl("Edit")?id={id}',width:'90%',height:'90%'">修改</button>
                    <button type="button" data-custom-params="url:'@Url.ActionUrl("Delete")',callBack:'LoadData'" class="btn btn-default btn-sm ui-deleteSingle btn_delete_is_{isDefault}">删除</button>
                </div>
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript">
    var tableId = Request("tableid");
    if (tableId == "")
    {
        tableId ="@ViewBag.TableId";
    }
    function LoadData()
    {
        if (tableId != "")
        {
         $("#tb_list").ListBind({ url: "@Url.ActionUrl("PageListData")?tableId=" + tableId, callBack: "LoadedInit" });
        }
    }
    LoadData();
</script>
